from tkinter import *
import random

root = Tk()
root.title("pyTimeManager")
root.iconbitmap('E:\\python_work\\pyTimeManager\\003.ico')

showSentences = 1

sentences = []
sentences.append("进程切换非常昂贵，避免多任务，保持单进程。")
sentences.append("研究表明，集中注意力、高效工作，每天最多4小时。")
sentences.append("划分任务的优先级，不要把'急切'当作'重要'。")
sentences.append("起床后，不要查看邮件和微信。")
sentences.append("避免开会，因为人类已知的最浪费时间的事情，就是开会。")
sentences.append("早晨4点起床，到了中午，你就完成了一天的任务。")
sentences.append("你没空时不会做的事情，有空了也不会做。")

def printList(event):
    print(lb.get(lb.curselection()))

def addNewClock():
	newClockUi = Toplevel()
	newClockUi.title("pyTimeManager - addNewClock")
	newClockUi.geometry('350x300')
	newClockUi.iconbitmap('E:\\python_work\\pyTimeManager\\003.ico')
	Label(newClockUi, text = "名称: ").grid(row=0, column=0)
	Label(newClockUi, text = "时间: ").grid(row=1, column=0)
	Label(newClockUi, text = "年/ ").grid(row=1, column=2)
	Label(newClockUi, text = " 月/ ").grid(row=1, column=4)
	Label(newClockUi, text = "日 ").grid(row=1, column=6)
	Label(newClockUi, text = " : ").grid(row=1, column=8)
	Label(newClockUi, text = " ").grid(row=2, column=0)
	Label(newClockUi, text = "重复：").grid(row=3, column=0)
	eName = Entry(newClockUi, width=38)
	eYear = Entry(newClockUi, width=6)
	eMonth = Entry(newClockUi, width=4)
	eDate = Entry(newClockUi, width=4)
	eHour = Entry(newClockUi, width=4)
	eMinute = Entry(newClockUi, width=4)
	eName.grid(row=0, column=1, columnspan=9)
	eYear.grid(row=1, column=1)
	eMonth.grid(row=1, column=3)
	eDate.grid(row=1, column=5)
	eHour.grid(row=1, column=7)
	eMinute.grid(row=1, column=9)
	options = []
	options.append(("只闹一次", 1))
	options.append(("每年", 2))
	options.append(("每月", 3))
	options.append(("每天", 4))
	options.append(("自定义", 5))
	v = IntVar()
	v.set(1)
	for option, num in options:
		b = Radiobutton(newClockUi, text = option, variable = v, 
			value = num, indicatoron = False, width = 10)
		b.grid(sticky = W)
	customizeSettings = setCustomize()
	customize = Button(newClockUi, text = "设置自定义",
		width = 10, command = customizeSettings.set)
	cancel = Button(newClockUi, text = "取消",
		width = 10, command = newClockUi.destory)
	determine = Button(newClockUi, text = "确定",
		width = 10, command = lambda: confirm({'clockName':eName.get(),
			'ringTime':[eYear.get(), eMonth.get(), eDate.get(), 
			eHour.get(), eMinute.get()], 'repeat':[v.get(), 
			customizeSettings.get()]}))
	

menubar = Menu(root)
clocks = [1,2,3,4,5,6,7,8,9]

def passer():
	pass

def about():
	aboutUi = Toplevel()
	aboutUi.title('about')
	aboutUi.iconbitmap('E:\\python_work\\pyTimeManager\\003.ico')
	label = Label(aboutUi, text="pyTimeManager        V1.1\nDate:2018.02.28")
	label.pack()

menubar.add_command(label = "新建闹钟", command = addNewClock)

encrmenu = Menu(menubar, tearoff=1)
encrmenu.add_command(label = "首选项", command = passer)
encrmenu.add_separator()
for clock in clocks:
	encrmenu.add_command(label = "设置闹钟%s" % clock, command = passer)

menubar.add_cascade(label = "设置", menu = encrmenu)

menubar.add_command(label = "关于...", command = about)
#menubar.add_command(label = "退出", command = root.quit)

sb = Scrollbar(root)
lb = Listbox(root, yscrollcommand = sb.set)
lb.bind('<Double-Button-1>',printList)
for clock in clocks:
    lb.insert(0,str(clock))
root.config(menu = menubar)
if showSentences:
	Label(root, text = random.choice(sentences)).pack(side=BOTTOM)
sb.pack(side = RIGHT, fill = Y)
lb.pack(fill=BOTH, side=LEFT, expand=True)
sb.config(command = lb.yview)

root.mainloop()